// Simple Particle System
// Daniel Shiffman <http://www.shiffman.net>

// A simple Particle class

class Particle {
  PVector location;
  PVector velocity;
  PVector acceleration;
  float lifespan;
  color c;
  float rotation;

  Particle(PVector loc, PVector accel, PVector vel, float rot) {
    acceleration = accel.get();
    velocity = vel.get();
    location = loc.get();
    lifespan = 255.0;
    c = color(random(50,255), random(50,255), random(50,255));
    rotation = rot;
  }

  void run() {
    update();
    display();
  }

  // Method to update location
  void update() {
    velocity.add(acceleration);
    location.add(velocity);
    lifespan -= 3f;
  }

  // Method to display
  void display() {
    pushMatrix();
    rotate(radians(rotation));
    noStroke();
    //fill(c, lifespan);
    fill(c);
    ellipse(location.x, location.y, 8, 8);
    popMatrix();
  }

  // Is the particle still useful?
  boolean isDead() {
    if (lifespan < 0.0) {
      return true;
    } 
    else {
      return false;
    }
  }
}

